﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Core.Logging;

namespace GuRenFang.Common
{
    /// <summary>
    /// need to set configuration like this:
    /// 
    //  <facilities>
    //     <facility id="logging" type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging" loggingApi="log4net" configfile="log4net.config" />
    //  </facilities>
    ///
    /// </summary>
   public class LoggerManager
    {
        private static object _synRoot = new Object();
        private ILoggerFactory _logFactory;
        private LoggerManager()
        {
            _logFactory = IocContainer.Instance.Resolve<ILoggerFactory>();
        }

        private static LoggerManager _loggerManager;
        public static LoggerManager Instance
        {
            get
            {
                if (_loggerManager == null)
                {
                    lock (_synRoot)
                    {
                        if (_loggerManager == null)
                        {
                            _loggerManager = new LoggerManager();
                        }
                    }
                }
                return _loggerManager;
            }
        }

        public ILogger DefaultLogger
        {
            get { return _logFactory.Create("Default"); }
        }

        public ILogger GetLogger()
        {
            return _logFactory.Create("Default");
        }

        public ILogger GetLogger(string loggerName)
        {
            return _logFactory.Create(loggerName);
        }

        public ILogger GetLogger(Type type)
        {
            return _logFactory.Create(type);
        }

        /// <summary>
        /// Reset the singleton
        /// </summary>
        public static void Reset()
        {
            _loggerManager = null;
        }
    }
}
